<%@ page import="java.sql.Connection" %>
<%@ page import="com.example.util.DBUtil" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.SQLException" %><%--
  Created by IntelliJ IDEA.
  User: ASUS
  Date: 2021/11/23
  Time: 20:46
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>查询学员信息</title>
</head>
<body>
获取到的姓名为:<%=session.getAttribute("compare")%><br>
<%
    try {
        Connection connection = DBUtil.getConnection();
        String sql = "select * from s_user";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        ResultSet resultSet = preparedStatement.executeQuery();
        while (resultSet.next()) {
            String sname = resultSet.getString("sname");
            if(session.getAttribute("compare").equals(sname)) {
                out.println("姓名:"+session.getAttribute("compare")+"的信息存在,查询成功!");
                sname = resultSet.getString("sname");
                String ssex = resultSet.getString("ssex");
                String sage = resultSet.getString("sage");
                String semail = resultSet.getString("semail");
                String stext = resultSet.getString("stext");
                out.println("<br>");
                out.println("查询的信息如下所示:");
                out.println("<br>");
                out.println(sname);
                out.println("<br>");
                out.println(ssex);
                out.println("<br>");
                out.println(sage);
                out.println("<br>");
                out.println(semail);
                out.println("<br>");
                out.println(stext);
                break;
            }
        }
    }catch(SQLException e){
        e.printStackTrace();
    }
%>
</body>
</html>
